package com.lmq.innerclasses;// innerclasses/Parcel3.java
// (c)2021 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://OnJava8.com for more book information.
// Using .new to create instances of inner classes

public class Parcel3 {
  class Contents {
    private int i = 11;
    public int value() { return i; }
  }
  class Destination {
    private String label;
    Destination(String whereTo) { label = whereTo; }
    String readLabel() { return label; }
  }
  public static void main(String[] args) {
    Parcel3 p = new Parcel3();
    // Must use instance of outer class
    // to create an instance of the inner class:
    Contents c = p.new Contents();
    Destination d =
      p.new Destination("Tasmania");
  }
}
/**
 * It's not possible to creat an object of the inner class unless you
 * already have an object of the outer class.This because the object of the inner class is quietly connected
 * to the object of the outer class it was made from.However, if you make a nested class (a static inner class), it
 * doesn't need a reference to the outer-class object.
 *
 * Inner classes and Upcasting
 * Inner classes become more interesting when you upcast to a base class,
 * and in particular to an interface.(The effect of producing an interface reference from an object that implements it is essentially the same as upcasting to a base class)
 * That's because the inner class the implementation of the interface can then be unseen and
 * unavailable, which is convenient for hiding the implementation All
 * you get back is a reference to the base class or the interface
 * We can create interfaces for the previous example:
 * {{{
 *     public interface Destination{
 *         String readLabel();
 *     }
 *     public interface Contents{
 *         int value();
 *     }
 * }}}
 * Now Contents and Destination represent interfaces available to the client programmer.
 * Remeber that an interface automatically makes all of its members public.
 * When you get a reference to the base class or the interface, it's
 * possible you can't even find out the exact type, as shown here:
 *
 *
 */